home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / What's New / Development Kits / Mac_OS_USB_DDK_v1.2 / Examples / PrinterClassDriver / PrinterClassDriver.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-15  |  7.8 KB  |  270 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PrinterClassDriver.h
  3.  
  4.     Contains:    structures for PrinterClass
  5.  
  6.     Version:    
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11. #ifndef __PRINTERCLASSDRIVERH__
  12. #define __PRINTERCLASSDRIVERH__
  13.  
  14. #include <MacTypes.h>
  15. #include <Devices.h>
  16. #include <DriverServices.h>
  17. #include <Processes.h>
  18.  
  19. #ifndef __MIXEDMODE__
  20. #include <mixedmode.h>
  21. #endif
  22.  
  23. #include <USB.h>
  24.  
  25. #if DEBUG
  26. #define IF_DEBUG(x)    x
  27. #else
  28. #define IF_DEBUG(x)
  29. #endif
  30.  
  31. #define kStrPrinterClass    "PrinterClass: "
  32. void DriverEntry(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  33. void ExpertNotify(void *exNote);
  34.  
  35. #define kPrinterRetryCount    5
  36.  
  37. /* Move to sys files */
  38. #define kUSBPrintClass 7
  39. #define kUSBPrintSubClass 1
  40.  
  41. #define TRANSFER_SIZE    4096 /* ideally this is the same as VM page size */
  42.  
  43. // section 5.3 USB Device Class Definition for Printing Devices
  44. enum {
  45.     kUSBPrintClassGetDeviceID = 0,
  46.     kUSBPrintClassGetCentronicsStatus = 1,
  47.     kUSBPrintClassSoftReset = 2,
  48.     kUSBPrintClassProtocolReserved = 0,
  49.     kUSBPrintClassProtocolUnidirectional = 1,
  50.     kUSBPrintClassProtocolBidirectional = 2,
  51.     // 3..0xFE reserved for future use
  52.     kUSBPrintClassProtocolVendor = 0xFF
  53. };
  54.  
  55. enum 
  56. {
  57.     kDrvrCentronicsStatus = 3,
  58.     kDrvr1284IdString = 4,
  59.     kDrvrNumDevices = 5,
  60.     kDrvrSoftReset = 6,
  61.     kDrvrPrivateSetStorage = 128
  62. };
  63.  
  64. enum driverstages
  65. {
  66.     kUndefined = 0,
  67.     kNilCompletion,
  68.     kFindInterface_bidirectional,
  69.     kFindInterface_unidirectional,
  70.     kOpenDevice,
  71.     kNewInterfaceRef,
  72.     kSetInterface,
  73.     kConfigureInterface,
  74.     kGetCapabilityString,
  75.     kDelayGetCapability,
  76.     kAllocateCapabilityMem,
  77.     kGetFullCapabilityString,
  78.     kGetInterface,
  79.     kFindBulkOutPipe,
  80.     kFindBulkInPipe,
  81.     kTaskTimeRequired,
  82.  
  83.     kGetCentronicsStatus,
  84.     kDelayGetCentronicsStatus,
  85.     
  86.     kDeallocateCapbilityString,
  87.  
  88.     kReturnFromDriver = 0x1000,
  89.     kRetryTransaction = 0x2000,
  90.     kTransactionPending = 0x8000
  91. };
  92.  
  93. enum {
  94.     uppIODoneProcInfo = kRegisterBased
  95.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  96.          | REGISTER_RESULT_LOCATION(kRegisterD0)
  97.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(OSErr)))
  98.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(IOParamPtr)))
  99.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterA1, SIZE_CODE(sizeof(DCtlHandle))),
  100.  
  101.     uppQueueUSBReadProcInfo = kCStackBased
  102.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  103.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  104.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  105.  
  106.     uppQueueUSBWriteProcInfo = kCStackBased
  107.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  108.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  109.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  110.  
  111.     uppAbortProcInfo = kCStackBased
  112.          | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
  113.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DriverRefNum)))
  114.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  115.  
  116.     uppControlStatusProcInfo = kCStackBased
  117.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  118.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  119.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *)))
  120. };
  121.  
  122. #if GENERATINGCFM
  123. typedef UniversalProcPtr    QueueUSBReadUPP;
  124. typedef UniversalProcPtr    QueueUSBWriteUPP;
  125. typedef UniversalProcPtr    IODoneUPP;
  126. typedef UniversalProcPtr    AbortUPP;
  127. typedef UniversalProcPtr    ControlStatusUPP;
  128. #else
  129. typedef ProcPtr                QueueUSBReadUPP;
  130. typedef ProcPtr                QueueUSBWriteUPP;
  131. typedef ProcPtr                IODoneUPP;
  132. typedef ProcPtr                AbortUPP;
  133. typedef ProcPtr                ControlStatusUPP;
  134. #endif
  135.  
  136. typedef struct {
  137.     OSErr        err;
  138.     IOParamPtr    pb;
  139.     DCtlPtr        ctl;
  140. } DrvrParams;
  141.  
  142. typedef union {
  143.     char            b;
  144.     struct {
  145.         unsigned    reserved0:2;
  146.         unsigned    paperError:1;
  147.         unsigned    select:1;
  148.         unsigned    notError:1;
  149.         unsigned    reserved1:3;
  150.     } status;
  151. } CentronicsStatusByte;
  152.  
  153. typedef struct usbPrinterPBStruct
  154. {
  155.     //
  156.     //    note: first element must be USBPB pb
  157.     //        since we often cast it to usbPrinterPBStruct
  158.     //
  159.     USBPB                             pb,                    // configuration block
  160.                                     out,                // map client write
  161.                                     in;                    // map client read
  162.     //
  163.     //    optional bulk in pipe
  164.     //
  165.     USBEndPointDescriptorPtr        readDescriptor;        // configuration/interface info
  166.     USBPipeRef                         readPipeRef;        // USB pipe reference
  167.     QueueUSBReadUPP                    qread,                // queue USB read from 68K
  168.                                     r;
  169.     RoutineDescriptor                qreadRD;            // static descriptor
  170.     DrvrParams                        readDrvr;            // currently active read
  171.     int                                readRetryCount;        // retry transactions
  172.     //
  173.     //    mandatory bulk out pipe
  174.     //
  175.     USBEndPointDescriptorPtr        writeDescriptor;    // configuration/interface info
  176.     USBPipeRef                         writePipeRef;        // USB pipe reference
  177.     QueueUSBWriteUPP                qwrite,                // queue USB write from 68K
  178.                                     w;
  179.     RoutineDescriptor                qwriteRD;            // static descriptor
  180.     DrvrParams                        writeDrvr;            // currently active read
  181.     int                                writeRetryCount;    // retry transactions
  182.     //
  183.     //    abort/cancel transactions
  184.     //
  185.     AbortUPP                        qabort,                // cancel from 68K DRVR
  186.                                     a;
  187.     RoutineDescriptor                qabortRD;            // static descriptor
  188.     //
  189.     //    status transactions
  190.     //
  191.     ControlStatusUPP                qstatus,            // simple status from 68K DRVR
  192.                                     s;
  193.     RoutineDescriptor                qstatusRD;            // static descriptor
  194.     DrvrParams                        statusDrvr;            // currently active status request
  195.     //
  196.     //    unit table driver names and refNums
  197.     //
  198.     DRVRHeaderHandle                hDrvr;                // detached from class driver resource file
  199.     DriverRefNum                    outRefNum;            // write unit table ref
  200.     DriverRefNum                    inRefNum;            // read unit table ref
  201.     Str255                            driverOutName;        // write driver name in unit table
  202.     Str255                            driverInName;        // read driver name in unit table
  203.     //
  204.     //    device: configuration and interface details
  205.     //
  206.     UInt8                            terminating;        // offline USS-720 device
  207.     USBDeviceRef                    deviceRef;            // USB device reference
  208.  
  209.     USBDeviceDescriptor                deviceDescriptor;
  210.     USBInterfaceDescriptorPtr        pInterfaceDescriptor;
  211.     UInt32                            interfaceOffset;    // result/param for USB calls
  212.     UInt8                            whichAltInterface;
  213.  
  214.     Str255                            devclass;            // printer class in name registry
  215.     Str255                            model;                // printer model in name registry
  216.     Str255                            name;                // printer name in name registry
  217.  
  218.     unsigned char                    *pCapabilityString;    // 1284 capability string
  219.     USBConfigurationDescriptorPtr    config;                // USB configuration string
  220.  
  221.     unsigned char                    capability[256];    // capability: try not to fragment storage
  222.     unsigned char                    configuration[256];    // configuration: try not to fragment storage
  223.  
  224.     CentronicsStatusByte            centronics;
  225.     //
  226.     //    we double-buffer i/o requests into our heap, using page aligned blocks
  227.     //
  228.     UInt32                            pageWriteAlignedBufferSize,
  229.                                     pageReadAlignedBufferSize;
  230.     UInt8                            *pageWriteAlignedBuffer,
  231.                                     *pageReadAlignedBuffer,
  232.                                     malignedBuffer[ 3*TRANSFER_SIZE ];    //PrintDriverEntry assumes 3*TRANSFER_SIZE
  233.  
  234.     //
  235.     //    class driver async transactions
  236.     //
  237.     SInt32                            transDepth;            // don't nest transactions
  238.     SInt32                             retryCount;            // automatically retry transactions
  239.  
  240.     USBReference                    interfaceRef;
  241.  
  242.     
  243.     UInt32                            configurationNumber;
  244.     UInt32                            interfaceNumber;
  245.     UInt32                            printerProtocol;
  246.     UInt32                            alternateSetting;
  247.     UInt32                            pipeCount;
  248.     
  249.     Boolean                            delayInProgress;
  250.     Boolean                            printerConfigured;
  251.     Boolean                            printerRegistered;
  252.     
  253. };  
  254.  
  255.    
  256. OSStatus OpenBulkEndpoint(struct usbPrinterPBStruct    *pPrinterPB, UInt32    refCon);
  257. OSStatus Abort( DriverRefNum refNum, struct usbPrinterPBStruct *pPrinterPB );
  258. void     ControlStatusRequests( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  259. void     QueueRead( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  260. void     QueueWrite( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  261.  
  262. void      PrintDriverEntry(USBDeviceRef deviceRef, USBDeviceDescriptorPtr desc, USBInterfaceDescriptorPtr pInterface, UInt32 interfaceNumber);
  263.  
  264. OSStatus PrinterRemovalNotification( void );
  265.  
  266. void    hexstr( int count, char *p, char *q );
  267.  
  268.  
  269.  
  270. #endif //__PRINTERCLASSDRIVERH__